package Week2.J0425;

// 动态规划

import java.util.Scanner;

// 找差值最大的两个数
//
public class 买卖股票的最好时机一_xv {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] days = new int[n];

        int max = scanner.nextInt();
        days[0] = max;
        int min = Integer.MAX_VALUE;
        int ret = 0;

        for (int i = 1; i < n; i++) {
            days[i] = scanner.nextInt();

            min = Math.min(min,days[i-1]);
            ret = Math.max(ret, days[i]-min);
        }
        System.out.println(ret);
    }
}
